/**
 * Copyright (c) 2006-2008, Julien PORTALIER
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright  Copyright (c) 2006-2008, Julien PORTALIER
 * @link       http://feather-cm.google.com/
 * @license    http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

_gettext_add_translations("fr",
{
	'Make public':              'Rendre publique',
	'Make private':             'Rendre privée',
	'Resource is now public.':  'La resource est maintenant publique.',
	'Resource is now private.': 'La resource est maintenant privée.',
	'An error occured.':        'Une erreur est survenue.'
});

var Publish = new Class(
{
	initialize: function()
	{
		$ES('a.private, a.public').addEvent('click', this.onAction.bindWithEvent(this));
	},
	
	onAction: function(evt)
	{
		var a = $(evt.target).addClass('waiting');
		new Ajax(evt.target.getAttribute('href'), {
			'method': 'get',
			'onSuccess': function(text)
			{
				a.removeClass('waiting');
				this[(a.hasClass('private')) ? 'afterPublic': 'afterPrivate'](a);
			}.bind(this),
			'onFailure': function(text)
			{
				a.removeClass('waiting');
				alert(_('An error occured.'));
			}.bind(this)
		}).request();
		evt.stop();
	},
	
	afterPrivate: function(a)
	{
		a.removeClass('public').addClass('private');
		a.setAttribute('href', a.getAttribute('href').replace(/\/0$/, '/1'));
		a.setAttribute('title', _('Make public'));
		alert('Resource is now private.');
	},
	
	afterPublic: function(a)
	{
		a.removeClass('private').addClass('public');
		a.setAttribute('href', a.getAttribute('href').replace(/\/1$/, '/0'));
		a.setAttribute('title', _('Make private'));
		alert('Resource is now public.');
	}
});

window.addEvent('domready', function() { new Publish(); });
